<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>所有权限</title>
<link href="../css/table.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery-1.8.3.min.js"></script>
<script>
		$(function(){
			loadType();
			$('#parentid').change(function(){
				loadAll();
			});
		});
			
		function loadType(){
			
			$.post('../getByPIDRight.action',{'right.parentid':''},function(data){
					$('#parentid').html('<option value="">父分组</option>');
					for(var i=0;i<data.length;i++){
						$('#parentid').append('<option value="'+data[i].id+'">'+data[i].name+'</option>');
				}
				loadAll();
			},'json');
			
		}
		
		function loadAll(){
			$('#tb').html('<tr><td colspan="3">loading...</td></tr>');
			$.post('../getByPIDRight.action',{'right.parentid':$('#parentid').val()},function(data){
					if(data.length==0){
						$('#tb').html('<tr><td colspan="3">暂无数据！</td></tr>');
					}else{
						$('#tb').html('');
					}
					for(var i=0;i<data.length;i++){
						$('#tb').append('<tr id="t'+data[i].id+'"><td>'+data[i].name+'</td><td>'+data[i].url+'</td><td><a href="javascript:void(0);" onclick="edit(\''+data[i].id+'\');">修改</a> &nbsp; <a onclick="del(\''+data[i].id+'\');">删除</a> </td></tr>');
					}
			},'json');
					
		}
		
		function edit(id){
			var editF = window.open('edit.jsp?id='+id,'修改','height=160,width=400,top=300,left=300,toolbar=no, modal=yes,menubar=no,scrollbars=no,resizable=no,location=no,status=no,z-look=yes,alwaysRaised=yes');
			editF.focus();
		}
		
		function del(id){
			var ok=confirm('确认删除？');
			if(ok){
				
				$.post('../deleteRight.action',{'right.rid':id},function(data){
					if(data=='1'){
						$('#t'+id).hide();
						loadType();
					}else{
						alert('操作失败！请重试!');
					}
				});	
			}
		}

</script>

</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<thead>
  <tr>
    <td colspan="4">权限分组：
      <label for="select"></label>
      <select name="right.parentid" id="parentid">
        <option value="">父分组</option>
      </select> &nbsp;<a href="add.html">新增</a> </td>
  </tr>
  <tr>
    <td width="150">名称</td>
    <td>URL</td>
    <td width="250">操作</td>
  </tr>
  </thead>
  <tbody id="tb">
      <tr>
        <td colspan="3">loading...</td>
      </tr>
  </tbody>
</table>
</body>
</html>
